package com.wx.network.sever;

import com.wx.network.codec.RpcClientDecoder;
import com.wx.network.codec.RpcClientEncoder;
import com.wx.network.handler.RpcServerHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import org.springframework.context.ApplicationContext;

public class RpcServerHandlerInitialzer extends ChannelInitializer<SocketChannel> {

    private ApplicationContext applicationContext;

    public RpcServerHandlerInitialzer(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        //添加编码器与解码器
        socketChannel.pipeline().addLast("encoder",new RpcClientEncoder());
        socketChannel.pipeline().addLast("decoder",new RpcClientDecoder());
    //    socketChannel.pipeline().addLast(new IdleStateHandler(7,7,7, TimeUnit.SECONDS));
        //添加业务处理类handler
        socketChannel.pipeline().addLast(new RpcServerHandler(applicationContext));
    }

}
